// $Id: sleep.c 329 2013-11-06 06:00:59Z alan.watson.f $

#define _POSIX_C_SOURCE 199309L

#include <errno.h>
#include <time.h>

#include "oaxaca-config.h"
#include "oaxaca.h"

void
oaxaca_sleep(long sec)
{
  struct timespec req, rem;
  req.tv_sec = sec;
  req.tv_nsec = 0;
  errno = 0;
  while (nanosleep(&req, &rem) == -1 && errno == EINTR) {
    errno = 0;
    req = rem;
  }
}

void
oaxaca_usleep(long usec)
{
  struct timespec req, rem;
  req.tv_sec = 0;
  req.tv_nsec = 1000 * usec;
  errno = 0;
  while (nanosleep(&req, &rem) == -1 && errno == EINTR) {
    errno = 0;
    req = rem;
  }
}
